import datetime


class ContactModel:

    def __init__(self, user):
        self.user_name = user.UserName
        self.nick_name = user.NickName
        self.remark_name = user.RemarkName
        self.signature = user.Signature
        self.user = user

    def __str__(self):
        return str(self.jsonfy())

    def jsonfy(self):
        d = dict(
            # user_name=self.user.UserName,
            nick_name=self.user.NickName,
            remark_name=self.user.RemarkName,
            signature=self.user.Signature,
        )
        return d


class RoomMemberModel:

    def __init__(self, member):
        self.user_name = member.UserName  # 标识
        self.nick_name = member.NickName  # 名称
        self.remark_name = member.RemarkName  # 备注名
        self.sex = member.Sex  # 1是男，2是女
        self.signature = member.Signature  # 个人签名
        self.active = 1
        self.leave_time = None
        self.member = member

    def __str__(self):
        return str(self.jsonfy(has_username=True))

    def jsonfy(self, has_username=False):
        d = dict(
            nick_name=self.nick_name,
            remark_name=self.remark_name,
            sex=self.sex,
            signature=self.signature
        )
        if has_username:
            d.update({"user_name": self.user_name})
        return d

    def leave_chatroom(self):
        self.active = 0
        self.leave_time = datetime.datetime.now()
